<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

use app\common\model\UserAccount;
use app\common\model\ApplicationClass;
use think\Db;

/**
 * Bank逻辑
 */
class FakeData extends LogicBase
{


    public function getFakeDataList($where = [], $field = 'a.*', $order = 'sort desc')
    {

        
        $this->modelFakeData->alias('a');
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        $count=$this->modelFakeData->where($where)->count();
        
        $list=$this->modelFakeData->alias('a')->join('__GAMBLER_KING_INVESTMENT__ g','a.product_id=g.id')->field($field.',g.name')->where($where)->paginate(10);
        return ['list'=>$list,'count'=>$count] ;
    }

    public function getWhere($data = [])
    {

        $where = [];

        !empty($data['search_data']) && $where['a.name'] = ['like', '%'.$data['search_data'].'%'];

        return $where;
    }


    public function FakeDataEdit($data = [])
    {

        $validate_result = $this->validateFakeData->scene('edit')->check($data);

        if (!$validate_result) {

            return [RESULT_ERROR, $this->validateFakeData->getError()];
        }

        $url = url('FakeDataList');

        
        
        // foreach($user_name as $k=>$v){
        //     $data['user_name']=$v;

        // Db::name("fake_data")->insert($data);
        //     // $this->modelFakeData->setInfo($data);
            
        // }
    $this->modelFakeData->setInfo($data);

        $handle_text = empty($data['id']) ? '新增' : '编辑';

        // $result && action_log($handle_text, 'FakeData' . $handle_text );
        return [RESULT_SUCCESS, 'FakeData操作成功', $url];
        // return $result ? [RESULT_SUCCESS, 'FakeData操作成功', $url] : [RESULT_ERROR, $this->modelFakeData->getError()];
    }


    public function getFakeDataInfo($where = [], $field = 'a.*')
    {

        $this->modelFakeData->alias('a');


        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        return $this->modelFakeData->getInfo($where, $field);
    }





}
